package thread;

import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolDemo {
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(3);
        for (int i = 0; i < 5; i++) {
            Runnable runnable = new Runnable() {
                public void run() {
                    Thread thread = Thread.currentThread();
                    System.out.println("正在执行");
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                    }
                    System.out.println("执行完毕");
                }
            };
            service.execute(runnable);
            System.out.println("交给线程一个任务");
        }
        service.shutdown();
        System.out.println("线程池关闭");
    }
}
